﻿/*** MikeWare Framework ************************************
* This class is part of product of MikeWare.Framework.
* 
* Author      : Mike Cheers
* Mail        : mikecheers@126.com
* Create Date : 2018/9/14
* Summary     : 
* 
* 
* Modified By : 
* Date        : 
* Mail        : 
* Comment     : 
**************************************************************/

namespace MikeWare.Components.MikeLoggor
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    public class Settings
    {
        public String Name { get; set; }
        public String Value { get; set; }
        public int IdentLevel { get; set; }
        public IList<Settings> Childen { get; set; }

        public override string ToString()
        {
            var builder = new StringBuilder();
            for (int i = 0; i < IdentLevel; i++)
            {
                builder.Append("\t");
            }
            builder.Append(Name + " : " + (Value ?? string.Empty));
            if (null != Childen && 0 < Childen.Count)
                foreach (var child in Childen)
                {
                    builder.Append(Environment.NewLine + child.ToString());
                }
            return builder.ToString();
        }

        internal bool FoundValueByName(string name, out string settingValue)
        {
            settingValue = null;

            if (Name.Equals(name)) { settingValue = Value; return true; }

            if (null == Childen || 0 == Childen.Count) return false;

            foreach (var setting in Childen)
            {
                if (setting.FoundValueByName(name, out settingValue))
                    return true;
            }

            return false;
        }
    }
}
